< previous page page_158 next page >

Page 158
Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSave_Click()
   If txtLast.Text = "" Then
      MsgBox "Last Name Must Be Filled In"
   End If
   If optMale.Value = True Then
      MsgBox "Employee is Male"
   Else
      MsgBox "Employee is Female"
   End If
   If cboState.Text = "CA" Then
      MsgBox "Employee can sign up for Health Care"
   ElseIf cboState.Text = "AZ" Then
      MsgBox "Employee is eligible for Bonus Programmer"
   ElseIf cboState.Text = "NV" Then
      MsgBox "Employee is eligible for 401k"
   End If
End Sub
The IIf( ) Function
The IIf() function allows you to combine an If...Then...Else statement into one line. The IIf() function accepts three parameters. If the first parameter evaluates to a True condition, the value of the second parameter is returned. If the first parameter evaluates to a False condition, the value of the third parameter is returned.
Heres the syntax:
9f31265bb40b592b1929e18a47ab28e5.gif
IIF(<Cond1 is True>, <Return Exp1>, <Else Return Exp2>)
Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim intTemp As Integer

intTemp = IIf(boolPerform, 1, 0)
Heres another example:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim strLast As String

strLast = IIf(strFirst = "Bill", "Gates", "Whoever")

 
< previous page page_158 next page >

If you like this book, buy it!